/**********************************************************
 * HD44780 Library
 * (c) Maksym Shevchenko <maksym.shevchenko@r0land.kiev.ua
 **********************************************************/

#ifndef LCD_H
#define LCD_H
 
// Control lines
#define LCD_RS_pin RC3
#define LCD_RW_pin RC4
#define LCD_E_pin  RC5
 
#define LCD_RS_tris TRISC3
#define LCD_RW_tris TRISC4
#define LCD_E_tris  TRISC5
 
// Data line 
#define LCD_DATA_pins PORTD
#define LCD_DATA_tris TRISD
 
#define lcd_cmd  0    // "command"
#define lcd_data 1    // "data"
#define lcd_line10   0x80 // first line
#define lcd_line20   0xC0 // second line

//LCD Commands
#define LCD_CMD_CLS         0b00000001 // �������� �����
#define LCD_CMD_HOME        0b00000010 // ������� ������
#define LCD_CMD_SETMODE     0b00000110
//                                 ||- S : 1-shift, 0-not shift
//                                 |-- ID: 1-Inc, 0-Dec
#define LCD_CMD_SETDISPLAY  0b00001100
//                                |||- B: 1-on, 0-off blinks
//                                ||-- C: 1-on, 0-off cursor
//                                |--- D: 1-on, 0-off display
#define LCD_CMD_SHIFT       0b00010000
//                               ||-- RL: 1-shift right, 0-shift left
//                               |--- SC: 1-display shift, 0-cursor move
#define LCD_CMD_SETFUNCTION 0b00111000
//                              |||- F: 1-5x10 dots, 0-5x8 dots
//                              ||-- N: 1-2 lines, 0-1 lines
//                              |--- DL:1-8 bits,  0-4 bits
#define LCD_CMD_SETCGADDR	0b01000000 // first CGRAM byte address
#define LCD_CMD_SETDDADDR	0b10000000 // first DDRAM bute address

/*void lcd_write(unsigned char data, unsigned char RSbit);
void lcd_writechr(unsigned char *arrayptr, int offset);
*/

void lcd_init();
void lcd_cls();
void lcd_gotoXY(char _x, char _y);
void putch(char data);

#endif
